package com.smfx.yxt.controller.teacher;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smfx.yxt.common.Const;
import com.smfx.yxt.common.RspResult;
import com.smfx.yxt.common.enums.Status;
import com.smfx.yxt.controller.BaseController;
import com.smfx.yxt.model.Grid;
import com.smfx.yxt.model.StudentSignUp;
import com.smfx.yxt.model.TeacherSignUp;
import com.smfx.yxt.page.OrderBy;
import com.smfx.yxt.page.Page;
import com.smfx.yxt.service.IStudentSignUpService;
import com.smfx.yxt.service.ITeacherSignUpService;
import com.smfx.yxt.vo.SignUpQueryVO;

/**
 * 查询报名信息
 */
@Controller
@RequestMapping(Const.TEACHER_ROLE + "/signUp")
public class SignUpController extends BaseController{

	@Autowired
	private IStudentSignUpService studentSignUpService;
	@Autowired
	private ITeacherSignUpService teacherSignUpService;
	
	private static Logger log = LoggerFactory.getLogger(SignUpController.class);

	/**
	 * 跳转到老师应聘信息列表页面
	 * */
	@RequestMapping("teacher")
	public String teacherSignUpList() {
		return "signUp/teaList";
	}
	/**
	 * 跳转到老师应聘信息详情页面
	 */
	@RequestMapping("teacher/detail")
	public String teacherDetail(@RequestParam(value = "id", required = true) Integer id,Model model) {
		try {
			TeacherSignUp info = teacherSignUpService.selectByPrimaryKey(id);
			  model.addAttribute("info", info);
		} catch (Exception e) {
			log.error("获取老师应聘信息失败----->>>>" + e.getMessage());
		}
		return "signUp/teaInfo";
	}
	
	/**
	 * 跳转到学生报名信息列表页面
	 * 
	 * */
	@RequestMapping("student")
	public String studentSignUpList() {
		return "signUp/stuList";
	}

	/**
	 * 跳转到学生报名信息详情页面
	 */
	@RequestMapping("student/detail")
	public String studentDetail(@RequestParam(value = "id", required = true) Integer id,Model model) {
		try {
			StudentSignUp info = studentSignUpService.selectByPrimaryKey(id);
            model.addAttribute("info", info);
		} catch (Exception e) {
			log.error("获取学生信息失败----->>>>" + e.getMessage());
		}
		return "signUp/stuInfo";
	}
	
	/**
	 * 获取学生的报名信息
	 * 
	 * @param 查询信息
	 * @return List<StudentSignUp>
	 */
	@ResponseBody
	@RequestMapping("student/page/query")
	public Object Students(SignUpQueryVO vo) {
		try {
			Page<StudentSignUp> page = new Page<StudentSignUp>();
			// 设置排序字段和方式
			List<OrderBy> sorts = new ArrayList<>();
			sorts.add(new OrderBy("SIGN_UP_TIME", "desc"));
			page.setParams(vo);
			page.setSorts(sorts);
			page.setPageNo(vo.getPage());
			page.setPageSize(vo.getRows());
			List<StudentSignUp> list = studentSignUpService.selectListByPage(page);
			Grid grid = new Grid();
			grid.setRows(list);
			grid.setTotal(page.getTotalRecord());
			return new RspResult(Status.SUCCESS, grid);
		} catch (Exception e) {
			log.error("get List<StudentSignUpVO>  error --->> {} " + e.getMessage());
		}
		return new RspResult(Status.FAIL, Status.FAIL.getMsg());
	}

	/**
	 * 
	 * 根据id查询学生报名信息
	 */
	@ResponseBody
	@RequestMapping("student/info")
	public Object studentDetail(@RequestParam(value = "id", required = true) Integer id) {

		try {
			StudentSignUp info = studentSignUpService.selectByPrimaryKey(id);

			return new RspResult(Status.SUCCESS, info);
		} catch (Exception e) {
			log.error("获取学生信息失败----->>>>" + e.getMessage());
		}
		return new RspResult(Status.FAIL, Status.FAIL.getMsg());
	}
	
	/**
	 * 分页获取应聘人的简历
	 */
	@ResponseBody
	@RequestMapping("teacher/page/query")
	public Object teacher(SignUpQueryVO vo) {
		try {
			Page<TeacherSignUp> page = new Page<>();
			page.setParams(vo);

			// 设置排序字段和方式
			List<OrderBy> sorts = new ArrayList<>();
			sorts.add(new OrderBy("SIGN_UP_TIME", "desc"));
			page.setSorts(sorts);
			page.setPageNo(vo.getPage());
			page.setPageSize(vo.getRows());
			List<TeacherSignUp> list = teacherSignUpService.selectListByPage(page);

			// 返回结果和总记录数
			Grid grid = new Grid();
			grid.setRows(list);
			grid.setTotal(page.getTotalRecord());
			return new RspResult(Status.SUCCESS, grid);

		} catch (Exception e) {
			log.error("get List<TeacherSignUp> error --->> " + e.getMessage());
		}
		return new RspResult(Status.FAIL, Status.FAIL.getMsg());
	}
	
	/**
	 * 
	 * 根据id查询应聘信息
	 */
	@ResponseBody
	@RequestMapping("teacher/info")
	public Object teacherDetail(@RequestParam(value = "id", required = true) Integer id) {

		try {
			TeacherSignUp info = teacherSignUpService.selectByPrimaryKey(id);

			
			return new RspResult(Status.SUCCESS, info);
		} catch (Exception e) {
			log.error("获取老师应聘信息失败----->>>>" + e.getMessage());
		}
		return new RspResult(Status.FAIL, Status.FAIL.getMsg());
	}
	
}
